﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Database.Model.Equipments>>" %>
<%@ Import Namespace="CRM.Models" %>
<%@ Import Namespace="CRM.Resourses" %>


<% 

       Html.DevExpress().GridView(settings =>
                                      {
                                          settings.Name = "gdEquipment";
                                          settings.KeyFieldName = "IdEquipment";
                                          settings.Settings.ShowFilterRow = true;

                                          settings.CallbackRouteValues =
                                          new { Action = "GetEquipEditCallBack" };

                                          settings.ClientSideEvents.SelectionChanged = "OnSelectionChangedInEquipments";
                                         // settings.ClientSideEvents.BeginCallback = "function(s,e){ alert(e.visibleIndex);  alert(e.isSelected);  if(e.isSelected){  var key = s.GetRowKey(e.visibleIndex); alert(key); e.customArgs['SelectedEquipmentId']=key;   }}";
                                          settings.SettingsBehavior.AllowSelectByRowClick = true;
                                          settings.SettingsBehavior.AllowSelectSingleRowOnly = true;

                                          settings.Columns.Add(column =>
                                          {
                                              column.FieldName = "IdEquipmentType";
                                              column.Caption = Resourses.EquipmentType;
                                              column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                              var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                              if (comboBoxProperties != null)
                                              {

                                                  comboBoxProperties.DataSource = DB.GetLocalizedEquipmentTypes();
                                                  //collection.EquipmentTypes;
                                                  comboBoxProperties.TextField = "LocaLizedString";
                                                  comboBoxProperties.ValueField = "Id";
                                                  comboBoxProperties.ValueType = typeof(int);
                                              }
                                          });

                                          settings.Columns.Add(column =>
                                          {
                                              column.FieldName = "IdVendor";
                                              column.Caption = Resourses.ToolVendor;
                                              column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                              var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                              if (comboBoxProperties != null)
                                              {

                                                  comboBoxProperties.DataSource =
                                                      DB.Vendors;

                                                  comboBoxProperties.TextField = "VendorName";
                                                  comboBoxProperties.ValueField = "IdVendor";
                                                  comboBoxProperties.ValueType = typeof(int);
                                              }
                                          });


                                          settings.Columns.Add(column =>
                                          {
                                              column.FieldName = "Model";
                                              column.Caption = Resourses.EquipmentModel;
                                              column.Settings.AutoFilterCondition =
                                                  AutoFilterCondition.Contains;
                                          });

                                       
                                      }).Bind(Model).GetHtml();
       
       
       
   %> 

   

